package com.eway.viewanimator;

import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class CustomInterpolatorActivity extends AppCompatActivity implements View.OnClickListener {
	private static String TAG=CustomInterpolatorActivity.class.getSimpleName();

	private TextView showInterpolaror;
	private Button startInterpolaror;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_custom_interpolator);


		showInterpolaror = (TextView) findViewById(R.id.show_interpolaror);
		startInterpolaror = (Button) findViewById(R.id.start_interpolaror);

		startInterpolaror.setOnClickListener(this);


	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.start_interpolaror:
				ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 400);
				valueAnimator.setDuration(2000);
				valueAnimator.setInterpolator(new MyInterpolator());

				valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
					@Override
					public void onAnimationUpdate(ValueAnimator animation) {
						int changeValue = (int) animation.getAnimatedValue(); // 不断改变的值
						showInterpolaror.layout(showInterpolaror.getLeft(),changeValue,showInterpolaror.getRight(),changeValue+showInterpolaror.getHeight());
					}
				});
				valueAnimator.start();
				break;
			default:
				break;
		}

	}


	/**
	 * 自定义插值器
	 */
	public class MyInterpolator implements TimeInterpolator {

		@Override
		public float getInterpolation(float input) {
			return input;
		}
	}
}
